package com.ctshk.app.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.BannerDTO;
import com.ctshk.rpc.cms.req.*;
import com.ctshk.rpc.cms.service.IBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * banner图管理 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "banner图管理-app", tags = "banner图管理-app")
@RestController
@RequestMapping("/banner-app")
public class BannerController extends BaseController {

    @DubboReference
    private IBannerService bannerService;

    @ApiOperation(value = "新增banner-app", notes = "新增banner-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid BannerAddReq req) {
        return bannerService.insert(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询banner-app", notes = "查询banner-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/queryById/{bannerId}")
    public Result<BannerDTO> queryById(@PathVariable("bannerId") String bannerId) {
        return bannerService.queryById(bannerId);
    }

    @ApiOperation(value = "分页查询banner-app", notes = "分页查询banner-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryList")
    public PageResponse<BannerDTO> queryList(@RequestBody @Valid BannerQueryReq req) {
        return bannerService.queryList(req);
    }

    @ApiOperation(value = "查询banners-app", notes = "查询banners-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryListByCode")
    public List<BannerDTO> queryListByCode(@RequestBody @Valid BannerPositionByTypeReq req) {
        return bannerService.queryListByCode(req);
    }

    @ApiOperation(value = "修改banner-app", notes = "修改banner-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid BannerUpdateReq req) {
        return bannerService.update(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改banner有效状态-app", notes = "修改banner有效状态-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/updateStatusById")
    public Result updateStatusById(@RequestBody @Valid UpdateStatusReq req) {
        return bannerService.updateStatusById(req);
    }
}
